﻿@page "/Template/CodeTemplate/CodeTemplateList2"

@using Modules.Template.Blazor.Pages.CodeTemplate.Components
@using Modules.Template.Shared.CodeTemplate
@inherits BasePage
@attribute [Authorize]

<PageTitle>@PageTitleString</PageTitle>

    <GridRow Align="middle" Style="height:48px;">
        <GridCol Span="12">
            @if (TableDataModel.TableOptions.IsEdit)
        {
            <Button OnClick="@AddClick" Icon="@IconType.Outline.Plus" Type="primary">添加</Button>
        }
    </GridCol>

    <GridCol Span="12">
        <div class="Table_Right_Tool">
            <Button Size="@ButtonSize.Small" Type="@ButtonType.Text" Icon="@IconType.Outline.Reload" OnClick="ResetTable">刷新</Button>
            @if (TableDataModel.TableOptions.IsEdit)
            {
                <Button Type="@ButtonType.Text" Size="@ButtonSize.Small" Icon="@IconType.Outline.Delete" OnClick="@BatchDelClick">批量</Button>
                <Button Size="@ButtonSize.Small" Type="@ButtonType.Text" Icon="@IconType.Outline.Edit">批量</Button>
            }
            <Button Type="@ButtonType.Text" Size="@ButtonSize.Small" Icon="@IconType.Outline.Setting" OnClick="@SettingTable">设置</Button>
        </div>
    </GridCol>
</GridRow>

<Table @ref="AntTable" Resizable
       RowClassName="@(x => x.Data.Row_CSS_Class)"
       HidePagination
        ScrollY="@TableOptions.ScrollY"
        Bordered="true"
        Size=@TableSize.Small
        TItem="CodeTemplateVM"
        DataSource="TableDataModel.TableModel.DataSource"
        @bind-PageIndex="TableDataModel.TableModel.PageIndex"
        @bind-PageSize="TableDataModel.TableModel.PageSize"
        @bind-SelectedRows="TableDataModel.TableModel.SelectedRows"
        Total="TableDataModel.TableModel.TotalCount"
        Loading="TableDataModel.TableModel.Loading"
        OnChange="HandleTableChangeAsync"
       RemoteDataSource>
    <ChildContent>
        <Selection Type="checkbox" />
        <ActionColumn Title="操作" Width="70">
            <Space Size="@($"1")">
                <SpaceItem>
                    <Button Size="@ButtonSize.Small" OnClick="()=>EditClick(context)" Type="@ButtonType.Link" Icon="@IconType.Outline.Edit" />
                </SpaceItem>
                <SpaceItem>
                    <Button Size="@ButtonSize.Small" OnClick="()=>DelClick(context)" Type="@ButtonType.Link" Icon="@IconType.Outline.Delete" />
                </SpaceItem>
            </Space>
        </ActionColumn>
        @*
        代码生成器会覆盖标记之间的内容。*@
        @*CodeGenerator start*@
        <AntDesign.Column @bind-Field="@context.Id" Hidden="@TableDataModel.GetColumnHidden("Id")" Width="@TableDataModel.GetColumnWidth("Id")" Sortable Filterable></AntDesign.Column>
         <AntDesign.Column @bind-Field="@context.Username" Hidden="@TableDataModel.GetColumnHidden("Username")" Width="@TableDataModel.GetColumnWidth("Username")" Sortable Filterable></AntDesign.Column>
         @*CodeGenerator end*@
     </ChildContent>
     <PaginationTemplate>
         <GridRow Align="middle" Style="height:40px;">
             <GridCol Span="12">
                 <Pagination Style="float:right;"
                             Total="context.Total"
                             Size="PaginationSize.Small"
                             ShowTotal=showTotal
                             PageSize="context.PageSize"
                             Current="context.PageIndex"
                             OnChange="context.HandlePageChange"
                             PageSizeOptions="TableDataModel.TableOptions.PageSizeOptions" />
             </GridCol>
             <GridCol Span="12">
                 <div style="text-align:right">
                 </div>
             </GridCol>
         </GridRow>
     </PaginationTemplate>
 </Table>

 <Modal Title="@Dialog.Title"
        @bind-Visible="@Dialog.Visible"
        Width="@Dialog.Width"
        Draggable="@Dialog.Draggable"
        
        Footer="null">
     <CodeTemplateAdd model="@EditRow" IsAdd="@IsAdd" OnValueCallback="OnValueCallback"></CodeTemplateAdd>
 </Modal>
 @*用户自定义列宽度*@
 <Modules.Core.Blazor.Components.UserColumnSetting UniqueID="@UniqueID" TableOptions="TableDataModel.TableOptions" ColumnHeaders="@TableDataModel.ColumnHeaderModels" userColumnDrawerVisible="@userColumnDrawerVisible" OnValueCallback="@OnUserColumnDrawerCallbackAsync"></Modules.Core.Blazor.Components.UserColumnSetting>

 @code
 {
    Func<PaginationTotalContext, string> showTotal = ctx => $"总计 {ctx.Total} 项";
}